﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="sooritakanne_pohikiri_v4", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(SooritakannePohikiriV4))]
    public class SooritakannePohikiriV4Serializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected ISooritakannePohikiriV4 clazz;
        
        public SooritakannePohikiriV4Serializer(ISooritakannePohikiriV4 clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("kinnitamise_aeg");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.KinnitamiseAeg))).ToString());
            Writer.WriteEndElement();
            if (clazz.PohikirjaTyyp!=null) {
                Writer.WriteStartElement("pohikirja_tyyp");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.PohikirjaTyyp))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Sisu!=null) {
                Writer.WriteStartElement("sisu");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Sisu))).ToString());
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="kinnitamise_aeg") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>sooritakanne_pohikiri_v4>kinnitamise_aeg");
                }
                clazz.KinnitamiseAeg = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("kinnitamise_aeg")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>sooritakanne_pohikiri_v4>kinnitamise_aeg", Reader.LocalName);
            }
            if (Reader.LocalName=="pohikirja_tyyp") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>sooritakanne_pohikiri_v4>pohikirja_tyyp");
                }
                clazz.PohikirjaTyyp = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("pohikirja_tyyp")).Value;
            }
            if (Reader.LocalName=="sisu") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>sooritakanne_pohikiri_v4>sisu");
                }
                clazz.Sisu = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("sisu")).Value;
            }
        }
    }
}
